% simple 9 point problem
clear; %clc;

D  = 0.2;
sa = 0.02;
del = 1.0;

A = 0.25 + 0.5*D/del; %A = 1;
B = -0.5*D/del;       %B =-1;
C = -D/del^2;
E = sa+4*D/del^2;

K = [ 1  -1   0   0   0   0   0   0   0   
      0   A   0   0   B   0   0   0   0
      0   1  -1   0   0   0   0   0   0 
      0   0   0   1  -1   0   0   0   0
      0   C   0   C   E   C   0   C   0
      0   0   0   0   1  -1   0   0   0
      0   0   0   0   0   0   1  -1   0
      0   0   0   0   B   0   0   A   0
      0   0   0   0   0   0   0   1  -1 ]
  
S = [ 0   0   0   0   1   0   0   0   0 ]';

phi = K\S;

for i=1:3
    for j=1:3
        k = i+(j-1)*( 3 );
        phimap(i,j)=phi(k);
    end
end

surf(phimap)